package ch.zhaw.swp1.model.message.body;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import ch.zhaw.swp1.model.message.validator.Validator;
import ch.zhaw.swp1.model.status.Status;
import ch.zhaw.swp1.model.status.error.MessageTextError;

/**
 * Generic class representing a message body
 * @author Daniel Tiefenauer
 */
public abstract class Body implements Validator, Serializable {
	
	/**
	 * Default version
	 */
	private static final long serialVersionUID = 1L;
	protected String messageText = "";

	protected List<Status> statusList = new ArrayList<Status>();
	
	/************************************************************************************/
	/* Constructors
	/*----------------------------------------------------------------------------------*/
	/**
	 * Default Constructor
	 */
	public Body(){
		messageText = "";
	}
	
	/**
	 * Constructor with parms
	 * @param messageText user entered message text
	 */
	public Body(String messageText){
		this.messageText = messageText;
	}
		
	/************************************************************************************/
	/* Methods
	/*----------------------------------------------------------------------------------*/
	/**
	 * Get a String representation of the body for printout to STDOUT
	 */
	public String toString(){
		return messageText;
	}
	
	/************************************************************************************/
	/* START Validation
	/*----------------------------------------------------------------------------------*/
	/**
	 * Validate message body
	 * @return a list of status objects (empty if validation is successful)
	 */
	public List<Status> validate(){
		statusList.clear();
		if(messageText.isEmpty()){
			statusList.add(new MessageTextError());
		}
		return statusList;
	}
	
	/**
	 * Check validity of message body
	 * @return true if the message body is valid, false if not
	 */
	public boolean isValid(){
		validate();
		return statusList.isEmpty();
	}
	/*----------------------------------------------------------------------------------*/
	/* END Validation
	/************************************************************************************/
	
	/************************************************************************************/
	/* START Getter/Setter
	/*----------------------------------------------------------------------------------*/
	public String getMessageText() {
		return messageText;
	}

	public void setMessageText(String messageText) {
		this.messageText = messageText;
	}
	/*----------------------------------------------------------------------------------*/
	/* END Getter/Setter
	/************************************************************************************/


}
